﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;

public class DrawFlyitemContent : MonoBehaviour
{
    public PaintBoard m_PaintBoard;
    public FlyingItemList m_FlyingItemList;
    Weapon m_Weapon;
    void Start()
    {
        //m_PaintBoard.gameObject.SetActive(false);
        m_FlyingItemList.m_DrawFlyItemContent = this;
    }

    // Update is called once per frame
    void Update()
    {

    }
    public void Init()
    {
        if(m_FlyingItemList.m_Items.Count > 0)
            m_FlyingItemList.SelectedItem(m_FlyingItemList.m_Items[0]);
        else
            m_PaintBoard.gameObject.SetActive(false);
    }
    public static Sprite CreateEmptSpriteOfFlyItem()
    {
        return Sprite.Create(new Texture2D(64, 128), new Rect(0, 0, 64, 128), new Vector2(0.5f, 0.5f));
    }
    public void Load(Weapon weapon)
    {
        m_Weapon = weapon;
        m_PaintBoard.imageSize = new Vector2Int(64, 128);
        m_FlyingItemList.Load(m_Weapon);
        if (m_Weapon.flyItems.Count == 0)
            m_PaintBoard.Hide();
        //var sprite = ResourcesManager.Instance.GetWeaponSprite(weapon.m_TypeID);
        //if (sprite == null)
        //    sprite = Sprite.Create(new Texture2D(64, 128), new Rect(0, 0, 64, 128), new Vector2(0.5f, 0.5f));
        //m_PaintBoard.SignImage(sprite);
    }
    public void ApplyData()
    {
        m_Weapon.ClearFlyItems();
        m_FlyingItemList.SelectedItem(null);//  空选一下，让最后画的画应用一下
        foreach (var i in m_FlyingItemList.m_Items)
        {
            m_Weapon.AddFlyItem(i.m_FlyItem);
            ResourcesManager.Instance.SetWeaponsFlyItemSprite(m_Weapon.typeID, i.m_FlyItem.flyItemID, i.m_Sprite);
        }
    }
    public void SetSprite(Sprite sprite)
    {
        m_PaintBoard.SetSprite(sprite);
    }
}